﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eCommerce.core.Helpers;
using eCommerce.db;
using eCommerce.core;
using eCommerce.db.BORespository;

namespace eCommerce.web.Ajax.Comment
{
    public partial class ListByArticle : System.Web.UI.Page
    {
        protected int Id;
        protected int TypeId;
        protected int PageIndex;
        protected int TotalRecords;
        protected string IsShowComment = "none";

        protected void Page_Load(object sender, EventArgs e)
        {
            Id          = Utils.GetIdFromRequestString(Utils.Id, 0);
            TypeId      = Utils.GetIdFromRequestString(Utils.TypeId, (int)CommentType.Article);
            PageIndex   = Utils.GetIdFromRequestString(Utils.PageIndex, Constant.PageIndex);

            if (!IsPostBack)
                if (Id > 0 && TypeId > 0 && PageIndex > 0)
                    ListCommentByIdTypeId();
        }

        private void ListCommentByIdTypeId()
        {
            var totalRecords = 0;
            var lstComment = CommentBo.PaginationComment(Id, TypeId, PageIndex, Constant.LittlePageSize, ref totalRecords);

            if (lstComment != null && lstComment.Count > 0)
            {
                TotalRecords = totalRecords;

                rptComment.DataSource = lstComment;
                rptComment.DataBind();

                IsShowComment = "block";

                ltPager.Text = PagerHelper.PageLinks(PageIndex, Constant.LittlePageSize, totalRecords, Constant.PageStep,
                                                        string.Format(UrlHelper.PagerCommentArticle, Id, TypeId, "{0}"));
            }
        }
    }
}